<template>
  <div class="mine">
   

    <!-- <div class="login-bg"> -->
        <p @click="show=!show">总产值 {{coinNow}}估值 ∨</p>
        <p>{{coinNowMoney}}</p>
    <!-- </div> -->



    <!-- 币种选择 -->
    <van-actionsheet v-model="show" :actions="actions" @select="onSelect"/>
  </div>
</template>
<script>
import { NavBar, Icon, Cell } from "vant";
import {
  coinType,
  coinAssets,
  totalIncomeAndWaitIncome
} from "../../../axios/api.js";
export default {
  components: {
    [NavBar.name]: NavBar,
    [Icon.name]: Icon,
    [Cell.name]: Cell
  },
  data() {
    return {
      coinNow: "",
      coinNowId: "234314",
      coinNowMoney: "",
      coinType: [],
    //   userName: "",
      show: false,
      actions: [],
    //   allMoney: "",
    //   moreMoney: "",
    //   loginShow:'1'
    };
  },
  mounted() {
    // console.log(this.$store.state.isLogin);
  },
  created() {
    this.getCoinType();
    this.getLostMoney();
  },
   watch: {
    //监听路由变化刷新数据
    $route(to, from) {
      this.getCoinType();
      this.getLostMoney();
    }
  },
  methods: {


    //获取余额
    getLostMoney() {
      var getCoins = {
        token: sessionStorage.getItem("token"),
        virtualWalletId: this.coinNowId
      };
      coinAssets({
        params: getCoins
      }).then(res => {
        console.log(res.data.data, 9999);
        if (res.data.data == null) {
          this.coinNowMoney = 0;
        } else {
          this.coinNowMoney = res.data.data.available_amount;
        }
      });
    },
    // 币种菜单
    onSelect(item) {
      // 点击选项时默认不会关闭菜单，可以手动关闭
      this.show = false;
      console.log(item);
      (this.coinNow = item.name),
        (this.coinNowId = item.id),
        this.getLostMoney(this.coinNowId);
      console.log(this.coinNowId);
    },
    getCoinType() {
      //获取币分类列表
      var that = this;
      coinType()
        .then(res => {
          console.log(res.data);
          that.coinType = res.data.data;
          that.actions = res.data.data;

          for (var i = 0; i < res.data.data.length; i++) {
            (that.actions[i].name = res.data.data[i].virtual_wallet_name),
              (that.actions[i].dataId = i);
          }
          that.coinNow = that.actions[1].name;
          that.coinNowId = that.actions[1].id;
        
        })
        .catch(function(err) {});
    },


  }
};
</script>
<style lang="less" scoped>
@import "../../../assets/less/variable.less";

</style>

